package ar.com.jendrix.common.web;

import javax.faces.event.ActionEvent;

import ar.com.jendrix.common.exception.ApplicationException;
import ar.com.jendrix.common.exception.SystemException;

@SuppressWarnings("serial")
public abstract class SearchBean extends BaseBean {

	/**
	 */
	public final void search(ActionEvent actionEvent) {
		//log.info("query");
		try {
			doSearch();
		} catch (ApplicationException a) {
			addErrorMessages(a.getMessages());
		} catch (Throwable t) {
			log.error(t.getMessage(), t);
			addErrorMessage("Error en la busqueda");
		}
	}

	/**
	 */
	protected abstract void doSearch() throws ApplicationException, SystemException;

	/**
	 */
	public final void export(ActionEvent actionEvent) {
		//log.info("export");
		try {
			doExport();
		} catch (ApplicationException a) {
			addErrorMessages(a.getMessages());
		} catch (Throwable t) {
			log.error(t.getMessage(), t);
			addErrorMessage("Error al exportar datos");
		}
	}

	/**
	 */
	protected void doExport() throws ApplicationException, SystemException {
	}
}